package com.ate.ui.fragments;


import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.ate.adapters.MainViewPagerAdapter;
import com.ate.ui.fragments2.OneFragment;
import com.ate.ui.fragments2.TwoFragment;
import com.ate.javamvp.R;
import com.ate.bean.GoodsBean;
import com.ate.javamvp.mvp.contract.Contract;
import com.ate.lib_core.http.mvp.view.BaseFragment;
import com.flyco.tablayout.SlidingTabLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;


public class MainFragment extends BaseFragment implements Contract.DataXiaView {
    private ViewPager pager;
    private SlidingTabLayout sliding;
    private String[] titles;
    private ArrayList<Fragment> fragmentList;
    private OneFragment oneFragment;
    private MainViewPagerAdapter mainViewPagerAdapter;
    private TwoFragment twoFragment;
    private LinearLayout viewpagerTop;
    private SmartRefreshLayout smart;

    @Override
    public int bandlayout() {
        return R.layout.fragment_main;
    }

    @Override
    public void initView() {
        pager = (ViewPager) findViewById(R.id.pager);
        sliding = (SlidingTabLayout) findViewById(R.id.sliding);
        viewpagerTop = (LinearLayout) findViewById(R.id.viewpager_top);
        smart = (SmartRefreshLayout) findViewById(R.id.smart);

        //,"上装","裤装","球鞋","女装","生活","潮玩","美妆"
        titles = new String[]{"有货", "上装"};
        if (fragmentList == null) {
            addFragment();

        }


        mainViewPagerAdapter = new MainViewPagerAdapter(getActivity().getSupportFragmentManager(), fragmentList);
        pager.setAdapter(mainViewPagerAdapter);
        sliding.setViewPager(pager, titles);
        smart.setEnableRefresh(false);

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Toast.makeText(getContext(), "创建", Toast.LENGTH_SHORT).show();
    }

    private void addFragment() {
        fragmentList = new ArrayList<>();
        oneFragment = new OneFragment();
        twoFragment = new TwoFragment();
        fragmentList.add(oneFragment);
        fragmentList.add(twoFragment);
    }


    @Override
    public void initData() {

    }


    @Override
    public void onSuccess(List<GoodsBean.DataBean> data) {

    }

    @Override
    public void onFail() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (fragmentList != null) {
            fragmentList.clear();
            fragmentList = null;
        }
        if (titles.length > 0) {
            titles.clone();
            titles = null;
        }

    }
}